package org.zfx.index01.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.zfx.index01.utils.EncryptAES;
import org.zfx.vo.Result;
import org.zfx.vo.ResultResponse;

@Slf4j
@RestController
@RequestMapping("/encrypt")
@Api(value = "EncryptController", tags = { "加密解密相关接口文档" })
public class EncryptController {

    @ApiOperation(value="aes_encrypt", notes = "AES加密")
    @RequestMapping(value = "/aes_encrypt", method = RequestMethod.POST)
    public Result encryptAES(@RequestBody() String data){
        System.out.println("encryptAES:"+data);
        return ResultResponse.success(EncryptAES.encryptAES(data));
    }

    @ApiOperation(value="aes_decrypt", notes = "AES解密")
    @RequestMapping(value = "/aes_decrypt", method = RequestMethod.POST)
    public Result aes_decryptAES(@RequestBody() String data){
        return ResultResponse.success(EncryptAES.decryptAES(data));
    }

    @ApiOperation(value="aes_getKey", notes = "获得Key")
    @RequestMapping(value = "/aes_getKey", method = RequestMethod.POST)
    public Result aesGetKey(){
        JSONObject result = new JSONObject();
        result.put("key",EncryptAES.key);
        result.put("iv",EncryptAES.iv);
        return ResultResponse.success(result);
    }
}